<?php


namespace xing\contentSafe;

use xing\contentSafe\core\BaseSafe;
use xing\contentSafe\core\ImageSafeInterFace;

require_once(dirname(__FILE__) . '/sdk/facepp-php-sdk/FppClient.php');
use Fpp\FppClient;

class FaceApp extends BaseSafe implements ImageSafeInterFace
{

    private $host = 'https://api-cn.faceplusplus.com';
    public $apiKey = '';
    public $apiSecret = '';
    public $scenes = [];
    public $returnLandmark = 2;
    public $sex = null;

    public function getClient()
    {
        return new FppClient($this->apiKey, $this->apiSecret, $this->host);
    }

    public function getImageInfo(array $urls, $taskIds = '')
    {

        $client = $this->getClient();

        $return = [];
        foreach ($urls as $k => $url) {
            $data = [
                'image_url' => $url,
                'return_landmark' => $this->returnLandmark,
                'return_attributes' => implode(',', $this->scenes),
            ];
            $result = $client->detectFace($data);
            if (empty($result->body['faces'])) return null;
            // 脸部
            foreach ($result->body['faces'] as $v) {
                foreach ($v['attributes'] as $label => $val) {
                    switch ($label) {
                        case 'beauty':
                            $return[$k][$label] = $val;
                            break;
                        default:
                            $return[$k][$label] = $val['value'];
                            break;
                    }
                }
            }
        }
        return $return;
    }
    public function getTextInfo(array $contents, $taskIds = '')
    {

    }
}